package com.imooc.jms.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.annotation.Resource;
import javax.jms.*;

/**
 * Created by spoplar on 17-7-27.
 */
public class ProducerServiceImpl implements ProducerService {

    @Autowired
    private JmsTemplate jmsTemplate;

    //@Resource(name = "queueDestination")
    @Resource(name = "topicDestionation")
    private Destination destination;

    public void sendMessage(final String message) {
        jmsTemplate.send(destination, new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
               TextMessage textMessage =  session.createTextMessage(message);
                System.out.println("发送了"+textMessage.getText());
                return textMessage;

            }
        });
    }
}
